package function.cutPrice;

import java.math.BigDecimal;
import java.util.Random;

public class CutPriceCal {

    private static Random random = new Random();

    private static Double totalMoney = 2200.0;

    private static Double cutPrice = 800.0;

    private static Double leastMoney = 1400.0;

    private static Double currentCutMoney = 0.0;

    Double singlePrice = 0.0;

    static void cutPrice() {
        int couldCutNum = new Double(totalMoney / 10).intValue(); // 总共可以砍的次数
        int currentNum = 1;// 已经看的次数
        Double base = 0.0; // 基础数据
        Double randomBase = 0.0; // 基础数据 * 100，不乘以100金钱数太小时或陷入第三个阶段，
        double plus; // 加的数
        Double sub; // 减得数
        int rate = 2; // 稳定度，越大越稳定
        while (leastMoney > 0) {
            if (totalMoney >= 2000) {
                if (currentNum <= 20) {
                    base = totalMoney * 0.5 * 0.05;
                    randomBase = base * 100;
                    plus = ((double) random.nextInt(randomBase.intValue())) / 100 / rate;
                    sub = base / rate / 2;
                    currentCutMoney = base + plus - sub;
                    System.out.println(currentCutMoney);
                } else if (currentNum > 20 && currentNum < 100) {
                    base = totalMoney * 0.49 * 0.0125;
                    randomBase = base * 100;
                    plus = ((double) random.nextInt(randomBase.intValue())) / 100 / rate;
                    sub = base / 2 / rate;
                    currentCutMoney = base + plus - sub;
                    System.out.println(currentCutMoney);
                } else { // 这个地方不要加限制
                    float x = 1.0f / (couldCutNum - 100);
                    base = totalMoney * 0.01 * x;
                    randomBase = base * 100;
                    plus = ((double) random.nextInt(randomBase.intValue())) / 100 / rate;
                    sub = base / 2 / rate;
                    currentCutMoney = base + plus - sub;
                    System.out.println(currentCutMoney);
                }
                ++currentNum;
            } else {

            }
            currentCutMoney = new BigDecimal(currentCutMoney).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            System.out.println(currentCutMoney);
            if (currentCutMoney > leastMoney) {
                currentCutMoney = leastMoney;
                System.out.println("砍价结束");
                System.out.println("一共砍了：" + currentNum + "次");
            }
            leastMoney = leastMoney - currentCutMoney;
        }
    }

    public static void main(String[] args) {
        cutPrice();
    }

}
